﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;

namespace IMap
{
    /// <summary>
    /// Marker.xaml 的交互逻辑
    /// </summary>
    public partial class Marker : UserControl
    {
        private PixelPoint BeforeMoveMousePoint,BeforeMoveElementPoint;
        //public int ZIndex
        //{
        //    get { return zIndex; }
        //    set
        //    {
        //        zIndex = value;
        //        Canvas.SetZIndex(this, zIndex);
        //    }
        //}   
        //private int zIndex;

        public Marker()
        {
            InitializeComponent();
            this.Width = 50;
            this.Height = 50;
        }        

        private void UserControl_MouseMove(object sender, MouseEventArgs e)
        {
            ((MapContainer)this.Parent).IsMoving = false;
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                double deltaX = e.GetPosition((UIElement)this.Parent).X - BeforeMoveMousePoint.X;
                double deltaY = e.GetPosition((UIElement)this.Parent).Y - BeforeMoveMousePoint.Y;
                Canvas.SetLeft(this, BeforeMoveElementPoint.X + deltaX);
                Canvas.SetTop(this, BeforeMoveElementPoint.Y + deltaY);
            }
        }

        private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {           
            ((MapContainer)this.Parent).IsMoving = false;
            BeforeMoveMousePoint = new PixelPoint(e.GetPosition((UIElement)this.Parent).X, e.GetPosition((UIElement)this.Parent).Y);
            BeforeMoveElementPoint = new PixelPoint(Canvas.GetLeft(this), Canvas.GetTop(this));            
        }

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {    
                ((MapContainer)this.Parent).layers_manager.Items(LayerType.Marker).Remove(this);
                Debug.Print("该控件已将被删除");          
        } 
    }
}
